/*
 *  
    Copyright (C) 2008  Nathaniel Waisbrot

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package termint.gui.vt;

import java.util.EventObject;

/**
 * The class of events representing changes to the VT display.
 * Changes only track which lines have changed, not individual characters.
 * Changes are represented as an array of booleans, one for each line of the vt.  An entry is
 * true if the line of the same index has changed.
 * @author Nathaniel Waisbrot
 *
 */
public class VTChangeEvent extends EventObject {
	protected boolean[] changed;
	protected boolean isConsumed;
	/**
	 * Create a new change event
	 * @param source the VT that produced this event
	 * @param changedLines array of lines which have changes
	 */
	public VTChangeEvent(VT320 source, boolean[] changedLines) {
		super(source);
		this.changed = changedLines.clone();
		this.isConsumed = false;
	}
	
	@Override
	public String toString() {
		String s = (changed[0] ? "0" : "");
		for (int i = 1; i < changed.length; i++) {
			if (changed[i]) {
				s = s+","+i;
			}
		}
		return s;
	}
	
	@Override
	public VT320 getSource() {
		return (VT320)(super.getSource());
	}
	
	/**
	 * Get the array of changed lines.  This is shared between all receivers.
	 * @return the array of changed lines
	 */
	public boolean[] getChanges() {
		return changed.clone();
	}
	
	/**
	 * Mark this event as consumed
	 */
	public void consume() {
		isConsumed = true;
	}
	
	/**
	 * Check if this event is consumed
	 * @return if this event is consumed
	 */
	public boolean isConsumed() {
		return isConsumed;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = -6272731816146569874L;

}
